package com.jyxd.web.controller.dictionary;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jyxd.web.data.common.Result;
import com.jyxd.web.data.dictionary.FrequencyDictionary;
import com.jyxd.web.data.user.User;
import com.jyxd.web.service.assessment.basic.FrequencyDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/dict/frequency")
@Slf4j
public class FrequencyDictionaryController {

    @Autowired
    private FrequencyDictionaryService frequencyDictionaryService;
    @Value("${server.port}")
    private String port;
    @PostMapping("/add")
    public Result<?> add(@RequestBody FrequencyDictionary frequencyDictionary) {
        boolean result = frequencyDictionaryService.save(frequencyDictionary);
        return Result.succeed(result);
    }

    @RequestMapping("/list")
    public Result<?> list() {
        QueryWrapper<FrequencyDictionary> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort_num");
        return Result.succeed(frequencyDictionaryService.list(queryWrapper));
    }

    @RequestMapping("/")
    public Result<?> index(HttpSession session){
        User user = (User)session.getAttribute("user");
        log.info("session port:{}",port);
        log.info("session user:{}",user.getUserName());
        return Result.succeed(true);
    }
}
